<!--
// Copy Right 2011 4 Xtreme Co.,Ltd.
// Author Kieatikun Sitiyoth pig.flashlight@gmail.com
// Author Chatcharin Pingkeaw EAA.Spectrumx@gmail.com
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" href="index.css" type="text/css" charset="utf-8" />
        <title>iLink</title>
    <script type="text/javascript" src="prototype.js"></script>
    <script  type="text/javascript">
    function test(){
        var username = $('form1').getInputs("text");
  	//alert(username[0].value);
        if(username[0].value==""){
            alert ("No input Text");
        }

        var password = $('form1').getInputs("password");
  	//alert(password[0].value);
        if(password[0].value==""){
            alert ("No input password");
	 }
	if((username[0].value!="")  && (password[0].value!="")){
  		document.form1.submit();
        }
    }
    </script>
    </head>
    <body background="image/bgw.png" style="background-repeat: no-repeat">
        
        <form id="form1" method="POST" action="">

            <div id="username">
            <input type="text" name="username"/>
            </div>

            <div id="password">
            <input type="password" name="password"/>
            </div>

            <div id="signin">
                <input type="submit" value="Login" name="submitx" onclick="test(this.value);" />
            </div>
       </form>

        <form action="regis.php" method="POST" id="form2">

            <div id="signup">
                <input type="submit" value="Regis" />
            </div>

        </form>
        <?php
            $username = $_POST[username];
                //echo $username;

            $password = $_POST[password];
                //echo $password;

            $x="0";

        $link = mysql_connect("localhost","root","");
        mysql_select_db("ilink");
        

	$result = mysql_query("SELECT username,password FROM iprofile WHERE username='$username' and password='$password'");
        
	while($linex = mysql_fetch_array($result)){
	//echo "<email>".$linex['username']."<br>";
	//echo "<email>".$linex['password']."<br>";
	$userdb=$linex[username]."<br>";
	$passdb=$linex[password]."<br>";
        if($userdb=="" || $passdb=="" && $username=="" || $password==""){
		echo "please enter username and password";
                $x="0";
		
	}
                $x="1";
        }
	mysql_close($link);
        ?>

        <script type="text/javascript">
            var jsvar=<?php echo $x; ?>;
            //alert(jsvar);
            if(jsvar=="1"){
                //alert("pass");
                setTimeout(function(){location.href = "http://localhost/WebiLink/roomlist.php";},1000);
            }
        </script>

    </body>
</html>
